﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using DAL;
using BLL;
namespace Web.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            //登录处理
            //获取 用户输入的用户名密码
            string username = this.TextBox_username.Text;
            string pswd = this.TextBox_pswd.Text;

            if (username == null || pswd == null)
            {
                this.Label1.Text = "用户名密码不能为空";
            }
            else
            {// "admin"
                //调用业务类的登录方法 " admin "  =》"admin" 
                UserInfo user = UserInfoBll.Login(username.Trim(), pswd.Trim());
                if (user != null)
                {//登录成功跳转页面
                    //2登录成功获取用户的角色码
                    string role = user.Role;//admin
                    //根据角色码去查找当前角色所拥有的权限 role表
                    Role roleObj= RoleBll.SelectOneByCode(role);
                    //将角色对象保存到session中
                    Session["role"] = roleObj;

                    //保存用户信息到session中
                    Session["user"] = user;
                    Response.Redirect("/Admin/Default.aspx");
                }
                else
                {
                    this.Label1.Text = "用户名密码错误";
                }
            }
        }

       
    }
}